<template>
  <div class="btn-demo-bg">
    <Bolts v-if="showBolts" />
    <button
      class="pikachu-btn"
      @mousedown="handleCry"
      @mouseup="isTearReady = false"
      @mouseleave="showBolts = false; isTearReady = false"
      @mouseover="showBolts = true; isTearReady = true"
      @mouseout="isTearReady = false"
    >
      <span class="eye eye-left" :class="{ blink: isBlinking }">
        <span class="tear" :class="{ 'tear-ready': isTearReady, 'tear-cry': isCrying }"></span>
      </span>
      <span class="eye eye-right" :class="{ blink: isBlinking }">
        <span class="tear" :class="{ 'tear-ready': isTearReady, 'tear-cry': isCrying }"></span>
      </span>
      <span class="cheek cheek-left"></span>
      <span class="cheek cheek-right"></span>
      <span class="btn-text">搜索</span>
    </button>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const showBolts = ref(false)
const isBlinking = ref(false)
const isTearReady = ref(false)
const isCrying = ref(false)

function blink() {
  isBlinking.value = true
  setTimeout(() => {
    isBlinking.value = false
    setTimeout(blink, 2000 + Math.random() * 2000)
  }, 120)
}

function handleCry() {
  isCrying.value = false
  setTimeout(() => {
    isCrying.value = true
    setTimeout(() => {
      isCrying.value = false
    }, 500)
  }, 10)
}

onMounted(() => {
  setTimeout(blink, 1000)
})
</script>

<style scoped>
.btn-demo-bg {
 
  background: #EAFEE9;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.pikachu-btn {
  position: relative;
  width: 220px;
  height: 80px;
  background: #FFDB8A;
  border: 6px solid #65336E;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'bw', 'Arial', sans-serif;
  font-size: 2rem;
  font-weight: bold;
  color: #65336E;
  outline: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: transform 0.1s;
}
.pikachu-btn:active {
  transform: translateY(3px);
}
.eye {
  position: absolute;
  top: 28px;
  width: 28px;
  height: 32px;
  background: #65336E;
  border-radius: 50%;
  transition: height 0.1s;
  overflow: visible;
}
.eye-left { left: 32px; }
.eye-right { right: 32px; }
.eye::after {
  content: '';
  display: block;
  position: absolute;
  left: 7px;
  top: 7px;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
}
.eye.blink {
  height: 8px;
  transition: height 0.1s;
}
.cheek {
  position: absolute;
  bottom: 12px;
  width: 18px;
  height: 18px;
  background: #F15C7E;
  border-radius: 50%;
}
.cheek-left { left: 12px; }
.cheek-right { right: 12px; }
.btn-text { z-index: 1; }
.tear {
  position: absolute;
  left: 50%;
  top: 70%;
  width: 8px;
  height: 14px;
  background: #6ec6ff;
  border-radius: 50%;
  opacity: 0;
  transform: translateX(-50%) scaleY(0.5);
  transition: 
    opacity 0.2s,
    transform 0.2s;
  z-index: 2;
}
.tear-ready {
  opacity: 0.7;
  transform: translateX(-50%) scaleY(1);
}
.tear-cry {
  opacity: 1;
  animation: tear-drop 0.5s cubic-bezier(.4,2,.6,1) forwards;
}
@keyframes tear-drop {
  0% {
    top: 70%;
    opacity: 1;
    transform: translateX(-50%) scaleY(1);
  }
  80% {
    top: 110%;
    opacity: 1;
    transform: translateX(-50%) scaleY(1.2);
  }
  100% {
    top: 120%;
    opacity: 0;
    transform: translateX(-50%) scaleY(1.2);
  }
}
</style>